def maxxes(a):
    if a == 1: return False
    test = True
    s = a-1
    while s>1:
        if not a % s:
            test = False
            break
        s -= 1
    return test

h = input()
r = []
for i in range(len(h)):
    for s in range(i + 1, len(h) + 1):
        a = int(h[i:s])
        if maxxes(a):
            r += [a]
print(max(r) if r else 0)
        
